<?php 
header('Content-type:text/html;charset=utf-8');
#计算阶乘
function factorial($num){
	if($num<=1){
		return 1;
	}else{
		return $num * j($num-1);
	}
}
#模拟array_push()函数
function myarray_push(&$array){
	var_dump(func_get_arg(1));
	for ($i=1; $i < func_num_args(); $i++) { 
		$array[] = func_get_args()[$i];
	}
	return count($array);
}
#模拟实现 array_walk 遍历对数组调用回调函数
function my_array_walk($array,$callback){
	foreach ($array as $key=>$item){
		$callback($item,$key);
	}
}
#模拟实现 array_map 遍历对数组调用回调函数
function my_array_map($callback,$array){
	$tmp = [];
	foreach($array as $key => $item){
		$tmp[] = $callback($item);
	}
	return $tmp;
}
#遍历多维数组，返回数组中所有元素键值对组合字符串，和遍历执行次数（数组元素数），
function my_print_r($array){
	static $tmp = '';
	static $count = 0;
	foreach($array as $key => $value){
		$count++;
		if(is_array($value)){
			my_print_r($value);
		}else{
			$tmp .= $key . '=>' . $value . "\n<br>" ;		}
	}
	return ['result'=>$tmp,'arr_number'=>$count];
}



$arr = array(
	['First'=>1,'Second'=>2,'Third'=>3,'Fourth'=>4],
	11,12,13,
	['John'=>21,'Tom'=>22,'Jesse'=>23],
	
);


$a = my_print_r($arr);

echo 'array: (<br>'.$a['result'].')<br>';
echo 'count: '.$a['arr_number'];


























